package dev.alm.ggzxservice.interceptor;

import dev.alm.ggzxservice.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        log.info("login interceptor prehandle");
        String token = request.getHeader("token");
        if (token == null) {
            throw new Exception("token is invalid");
        }
        String username = JwtUtils.parseJwtToken(token);
        if (Strings.isEmpty(token)) {
            throw new Exception("token is invalid");
        }
        return true;
    }

}
